<div id="search">
	<% form_for(@search, {:id => "search_form"}) do |f| %>
	    Search: <%= f.text_field(:query, {:id => "query"}) %>
		&nbsp;<%= link_to("Clear", clear_searches_path) %>&nbsp;|
		<% unless @search.new_record? %>
			<% if @search.is_saved? %>
				<%= link_to("Unsave as Trend", unsave_search_path(@search)) %>
			<% else %>
				<%= link_to("Save as Trend", save_search_path(@search)) %>
			<% end %>
			|
		<% end %>
		<%= render("searches/example_search_link") %>
		| <%= link_to("Pertinent Only", search_path(@impt_search)) %>
		<input type="hidden" name="ref" value="reports">
	<% end %>
	<%= render("searches/example_searches") %>
</div>

<%= flash_and_form_errors %>

<%= render("table_only", :reports => @reports) %>

<div id="picker" style="display: none;"></div>


<script language="javascript">
function show_picker(report_id, page) {
	// get partial
	new Ajax.Updater('picker', '/incidents/picker', {
	  parameters: { report_id: report_id, page: page }, method: "get",
	  onComplete: function () {
		// size and position div
		$('picker').show();
		$('picker').style.top = Math.max(50, document.viewport.getScrollOffsets().top + 50) + "px";
		$('picker').style.left = "150px";
		$('picker').style.width = (document.viewport.getDimensions().width - 200) + "px";
		$('picker').style.height = (document.viewport.getDimensions().height - 100) + "px";
		
		// fix pagination links
		var links = $('picker_pagination').getElementsByTagName('a');
		
		for (var i = 0; i < links.length; i++)
			links[i].onclick = function() { 
				var m = /page=(\d+)&report_id=(\d+)/.exec(this.href)
				show_picker(m[2], m[1]); 
				return false; 
			}
	  }
	});
}

function cancel_picker() {
	$('picker').hide();
}
</script>